<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2017 河源市卓锐科技有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------

namespace app\common\model;

use think\Db;
use think\Model as ThinkModel;

//房间等位模型
class Wait extends ThinkModel
{
    // 设置当前模型对应的完整数据表名称
    protected $table = '__QT_WAIT__';
    protected $name = 'qt_wait';
    protected $pk = 'id';
    protected $autoWriteTimestamp = true;

    /**
     * 添加等位或者延迟排钟
     * @param $getData
     * @param $storeInfo
     * @param $projectName
     * @param $sex
     * @param $number
     * @param $userInfo
     */
    public static function setWait($getData,$storeInfo,$projectName,$sex,$number,$userInfo){
        if($getData['order_type'] == '1' && $storeInfo['is_auto_queue'] == '0'){
            $roomOrder = [
                'store_id'=>$userInfo['store_id'],
                'room_id'=>$getData['room_id'],
                'project_id'=>$getData['project_id'],
                'project_name'=>$projectName,
                'sex'=>$sex,
                'number'=>$number,
                'create_id'=>$userInfo['id'],
                'create_time'=>time(),
            ];
            Db::name('qt_wait')->insert($roomOrder);
            return true;
        }
        //延时排钟记录
        if($getData['time_type'] == '2'){
            if(empty($getData['delay'])){
                return false;
            }
            $roomOrder = [
                'store_id'=>$userInfo['store_id'],
                'room_id'=>$getData['room_id'],
                'project_id'=>$getData['project_id'],
                'project_name'=>$projectName,
                'sex'=>$sex,
                'number'=>$number,
                'create_id'=>$userInfo['id'],
                'delay_time'=>$getData['delay'],
                'create_time'=>time(),
            ];
            Db::name('qt_wait')->insert($roomOrder);
            return true;
        }
        return false;
    }

}